package work.mediway.bi.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mediway.hos.base.model.BaseResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import work.mediway.bi.model.dto.BiDesignTemplateDTO;
import work.mediway.bi.model.entity.DesignTemplate;
import work.mediway.bi.model.vo.BiDesignTemplateVO;
import work.mediway.bi.service.DesignTemplateService;

import javax.annotation.Resource;

/**
 * @author bovane <bovane.ch@gmail.com>
 * @description
 * @create 2023-06-15 14:44
 */
@Slf4j
@RestController
@RequestMapping("/bi/template")
public class BiDesignTemplateController {

    @Resource
    private DesignTemplateService designTemplateService;

    /**
     * 获取BI模版详细信息
     */
    @GetMapping()
    public BaseResponse getInfo(BiDesignTemplateDTO biDesignTemplateDTO) {
        IPage<BiDesignTemplateVO> result =  this.designTemplateService.getBiDesignTemplate(biDesignTemplateDTO);
        return BaseResponse.success(result);
    }


    /**
     * 新增BI模版信息
     */
    @PostMapping
    public BaseResponse add(@RequestBody DesignTemplate designTemplate) {
        //保存基本信息
        Boolean result = this.designTemplateService.addBiDesignTemplate(designTemplate);
        return result ? BaseResponse.success(): BaseResponse.error();
    }

    /**
     * 更新BI模版信息
     */
    @PutMapping
    public BaseResponse edit(@RequestBody DesignTemplate designTemplate) {
        Boolean result = this.designTemplateService.updateBiDesignTemplate(designTemplate);
        return result ? BaseResponse.success(): BaseResponse.error();
    }

    /**
     * 删除BI模版信息,多条则以 "," 作为分割
     */
    @DeleteMapping("/{ids}")
    public BaseResponse remove(@PathVariable String ids) {
        this.designTemplateService.deleteBiDesignTemplate(ids);
        return BaseResponse.success();
    }
}
